<?php
/**
 * Created by PhpStorm.
 * User: 风哀伤
 * Date: 2020/2/26
 * Time: 10:18
 * @copyright: ©2019 浙江禾匠信息科技
 * @link: http://www.zjhejiang.com
 */

namespace app\controllers;

use app\jobs\UpdateJob;

class UpdateController extends Controller
{
    public function actionUpdate()
    {
        $v = \Yii::$app->request->get('v');
        if (!$v) {
            throw new \Exception('请输入更新sql的版本');
        }
        // 运行各个版本的升级脚本
        $versions = require \Yii::$app->basePath . '/versions.php';
      	$f = $versions[$v];
       	if ($f instanceof \Closure) {
       		$f();
          	dd('执行成功');
       	} else {
            throw new \Exception('未执行sql');
        }
    }

    public function actionUpdateJob()
    {
        \Yii::$app->queue3->delay(20)->push(new UpdateJob());
    }
}
